package com.sky.mapper;

import com.sky.aop.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    @Select("select * from dish where category_id  = #{categoryId}")
    List<Dish> list(Dish dish);

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insertDish(Dish dish);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> selectDishPage(DishPageQueryDTO dishPageQueryDTO);


    /**
     * 批量删除（删除菜品）
     * @param id
     */
    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * 批量删除（是否存在起售中的菜品）
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish selectDishById(Long id);

    /**
     * 批量删除（是否被套餐关联了）
     * @param ids
     * @return
     */
    Long selectCountByDishIds(List<Long> ids);


    @Select("select * from dish where id = #{id}")
    Dish selectById(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param dish
     * @return
     */
    List<Dish> dishByCategoryId(Dish dish);


     void updateStatusById(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
